import config from "@/config/index";
import api from "@/api/index";
import tool from "@/utils/tool";

import auth from "@/directives/auth";
import role from "@/directives/role";
import errorHandler from "@/utils/errorHandler";

import * as elIcons from "@element-plus/icons-vue";

export default {
  install(app) {
    //注册vue全局变量
    app.config.globalProperties.$CONFIG = config;
    app.config.globalProperties.$API = api;
    app.config.globalProperties.$TOOL = tool;

    //统一注册el-icon图标
    for (let icon in elIcons) {
      app.component(`ElIcon${icon}`, elIcons[icon]);
    }

    //注册全局指令
    app.directive("auth", auth);
    app.directive("role", role);

    //关闭async-validator全局控制台警告
    window.ASYNC_VALIDATOR_NO_WARNING = 1;

    //全局代码错误捕捉
    app.config.errorHandler = errorHandler;
  },
};
